﻿@using WebAPP.MateralUI.Models
<div class="@ClassString">
    @if (!string.IsNullOrWhiteSpace(Title))
    {
        if (IsRequired)
        {
            <label class="m_form_label"><span class="m_form_label_required">*</span>@Title</label>
        }
        else
        {
            <label class="m_form_label">@Title</label>
        }
    }
    @ChildContent
    @if (PropertyModel != null && PropertyModel.CanError)
    {
        <span class="m_form_error_message">@PropertyModel.ErrorMessage</span>
    }
</div>

@code {
    #region 参数
    /// <summary>
    /// 自定义Class
    /// </summary>
    [Parameter]
    public string Class { get; set; } = string.Empty;
    /// <summary>
    /// 按钮内部
    /// </summary>
    [Parameter]
    public RenderFragment ChildContent { get; set; }
    /// <summary>
    /// 标题
    /// </summary>
    [Parameter]
    public string Title { get; set; }
    /// <summary>
    /// 必填标识
    /// </summary>
    [Parameter]
    public bool IsRequired { get; set; } = false;
    /// <summary>
    /// 属性模型
    /// </summary>
    [Parameter]
    public IFromDataPropertyModel PropertyModel { get; set; }
    #endregion
    #region 属性
    /// <summary>
    /// Class字符串
    /// </summary>
    public string ClassString
    {
        get
        {
            var result = "m_form_item";
            if (PropertyModel != null && PropertyModel.CanError)
            {
                result += " error";
            }
            if (!string.IsNullOrWhiteSpace(Class))
            {
                result += $" {Class}";
            }
            return result;
        }
    }
    #endregion
}
